package aidturith.db.beans;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "album_table")
public class Album {

	@Id
	@GeneratedValue
	@Column(name = "album_id")
	private int album_id;

	@Column(name = "album_tile", nullable = false, updatable = true, unique = false)
	private String album_title;

	@Column(name = "album_date", nullable = true, updatable = true, unique = false)
	private Date album_date;

	@Column(name = "album_ref", nullable = true, updatable = true, unique = true)
	private String album_ref;

	@Column(name = "album_type", nullable = false, updatable = true, unique = false)
	private String album_type;

	@OneToMany(mappedBy="album")
	@Cascade({CascadeType.ALL})
	private Set<Music> musics = new HashSet<Music>();

	@ManyToOne
	@JoinColumn(name = "id_cover")
	private Cover cover;

	@ManyToMany(mappedBy="albums")
	private Set<Circle> circles = new HashSet<Circle>();

	@ManyToOne
	@JoinColumn(name = "id_event")
	private Event event;

	public Album() {
		super();
	}

	public Album(String album_title, String album_ref, String album_type) {
		super();
		this.album_title = album_title;
		this.album_ref = album_ref;
		this.album_type = album_type;
	}

	public Album(String album_title, String album_type) {
		super();
		this.album_title = album_title;
		this.album_type = album_type;
	}

	public String getAlbum_title() { return album_title; }
	public void setAlbum_title(String album_title) { this.album_title = album_title; }

	public Date getAlbum_date() { return album_date; }
	public void setAlbum_date(Date album_date) { this.album_date = album_date; }

	public String getAlbum_ref() { return album_ref; }
	public void setAlbum_ref(String album_ref) { this.album_ref = album_ref; }

	public String getAlbum_type() { return album_type; }
	public void setAlbum_type(String album_type) { this.album_type = album_type; }

	public Set<Music> getMusics() { return musics; }
	public void setMusics(Set<Music> musics) { this.musics = musics; }

	public void addMusic(Music music) {
		getMusics().add(music);
		music.setAlbum(this);
	}

	public Cover getCover() { return cover; }
	public void setCover(Cover cover) { this.cover = cover; }

	public Set<Circle> getCircles() { return circles; }
	public void setCircles(Set<Circle> circles) { this.circles = circles; }

	public void addCircle(Circle circle) {
		getCircles().add(circle);
		circle.getAlbums().add(this);
	}

	public Event getEvent() { return event; }
	public void setEvent(Event event) { this.event = event; }

	@Override
	public String toString() { return album_title; }

}
